import 'package:flutter/material.dart';
import 'package:cached_network_image/cached_network_image.dart';


/// 构建比例显示的网络图片
Widget buildAspectImg(String imgUrl, double aspectRatio) {
  return AspectRatio(
    aspectRatio: aspectRatio,
    child: CachedNetworkImage(
      fit: BoxFit.cover,
      imageUrl: imgUrl,
      // 圆角效果实现
      imageBuilder: (context, imageprovider) => Container(
        decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(10),
            image: DecorationImage(image: imageprovider, fit: BoxFit.cover)),
      ),
      placeholder: (
        BuildContext context,
        String url,
      ) =>
          Container(
        color: Color(0xFFD6D6D6),
        child: Center(
          child: SizedBox(
            width: 30,
            height: 30,
            child: CircularProgressIndicator(
              color: Colors.blueGrey,
            ),
          ),
        ),
      ),
    ),
  );
}
